package com.ruoyi.framework.minio;

import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class MinIoClientConfig {
    @Value("${minio.endpoint}")
    private String endpoint;
    @Value("${minio.endpointOuter}")
    private String endpointOuter;
    @Value("${minio.accessKey}")
    private String accessKey;
    @Value("${minio.secretKey}")
    private String secretKey;
    @Value("${minio.bucketName}")
    private String bucketName;

    public String getBucketName() {
        return bucketName;
    }

    public void setBucketName(String bucketName) {
        this.bucketName = bucketName;
    }

    /**
     * 注入minio 客户端
     * @return
     */
    @Bean
    public MinioClient minioClient(){
        return MinioClient.builder()
                .endpoint(endpoint)
                .credentials(accessKey, secretKey)
                .build();
    }
    @Bean(name = "minioClientOuter")
    public MinioClient minioClientOuter(){
        return MinioClient.builder()
                .endpoint(endpointOuter)
                .credentials(accessKey, secretKey)
                .build();
    }

    public String getFileUrl(String bucketName,String objectName){
        return endpoint+"/"+bucketName+"/"+objectName;
    }
}

